ifeq ($(HB_QUIET), y)
export HB_ECHO = @
else
export HB_ECHO =
endif

export CC				= $(HB_ECHO)$(CROSS_COMPILE)gcc
export AR				= $(HB_ECHO)$(CROSS_COMPILE)ar
export RANLIB			= $(CROSS_COMPILE)ranlib
export STRIP			= $(CROSS_COMPILE)strip
export CONFIGURE_HOST	= $(subst @,,$(subst -gcc,,$(CC)))

ifneq (,$(findstring openssl, $(PWD)))
export AR += rv
endif

ifeq ($(PLATFORM), x86)
export HBLIB_PATH			=$(TOP_DIR)/lib_x86
endif

ifeq (,$(findstring openssl, $(PWD)))
ifeq (,$(findstring wpa_supplicant, $(PWD)))
export CFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -rdynamic -O2 -Wall -I$(HBINC_PATH) -L$(HBLIB_PATH) \
	-I$(TOP_DIR)/inc/video -I$(TOP_DIR)/inc/audio -I$(TOP_DIR)/inc/devlib -I$(TOP_DIR)/inc/network \
	-I$(TOP_DIR)/inc/base/ -I$(TOP_DIR)/inc/mfs/ -I$(TOP_DIR)/inc/pciv/ -I$(TOP_DIR)/inc/sys/ -I$(TOP_DIR)/inc/gui/ \
	-I$(TOP_DIR)/inc/json/ -I$(TOP_DIR)/inc/upgrade/
endif
else
endif

########################################
#
# Enable network diagnosis
#
########################################
CFLAGS				+= -DNETWORK_DIAGNOSIS_ENABLE

########################################
#
# Debug param
#
########################################
ifeq ($(DEBUG), y)
export DEBUG		= Y
CFLAGS				+= -DERR_DEBUG -g3
else
export DEBUG		= N
endif 

ifeq ($(P2P_USE_STR), HBYDT)
CFLAGS				+= -DENABLE_HBYDT
else
ifeq ($(P2P_USE_STR), DANALE)
CFLAGS				+= -DENABLE_DANALE
endif
endif

ifeq ($(MMGR_HOOK_MODE), true)
CFLAGS				+= -DMMGR_HOOK_MODE
endif

ifeq ($(PLATFORM), HI3531)
ifeq (${SDK_HISIL_3531},)
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3531 Sdk $(SDK_HISIL_3531_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3531 -DHBFL_SUPPORT_PCIV
CORE_FLAGS			= -march=armv7-a -mcpu=cortex-a9 -mfloat-abi=softfp -mfpu=vfpv3-d16
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3521)
ifeq (${SDK_HISIL_3521},) 
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3521 Sdk $(SDK_HISIL_3521_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3521
CORE_FLAGS			= -march=armv7-a -mcpu=cortex-a9
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3521A)
ifeq (${SDK_HISIL_3521A},)
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3521A Sdk $(SDK_HISIL_3521A_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3521A
CORE_FLAGS			= -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3520A)
ifeq (${SDK_HISIL_3520A},) 
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3520A Sdk $(SDK_HISIL_3520A_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3520A
CORE_FLAGS			= -march=armv7-a -mcpu=cortex-a9
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3520D)
ifeq (${SDK_HISIL_3520D},)
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3520D Sdk $(SDK_HISIL_3520D_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3520D
CORE_FLAGS			= -march=armv7-a -mcpu=cortex-a9
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3520D_V300)
ifeq (${SDK_HISIL_3521A},)
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3520D V300 Sdk $(SDK_HISIL_3521A_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3520D_V300
CORE_FLAGS			= -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3531A)
ifeq (${SDK_HISIL_3531A},)
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3531A Sdk $(SDK_HISIL_3531A_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3531A
CORE_FLAGS			= -mcpu=cortex-a9 -mfloat-abi=softfp -mfpu=neon -mno-unaligned-access -fno-aggressive-loop-optimizations
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3516C)
ifeq (${SDK_HISIL_3516C},) 
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3516C Sdk $(SDK_HISIL_3516C_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3516C
CORE_FLAGS			= -march=armv5te
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3520A_UCLIBC)
ifeq (${SDK_HISIL_3520A_UCLIBC},) 
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3520A_UCLIBC Sdk $(SDK_HISIL_3520A_UCLIBC_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3520A
CORE_FLAGS			= -march=armv7-a -mcpu=cortex-a9
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3521_UCLIBC)
ifeq (${SDK_HISIL_3521_UCLIBC},) 
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3521_UCLIBC Sdk $(SDK_HISIL_3521_UCLIBC_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3521
CORE_FLAGS			= -march=armv7-a -mcpu=cortex-a9
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3535)
ifeq (${SDK_HISIL_3535},)
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3535 Sdk $(SDK_HISIL_3535_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3535 -DHBFL_SUPPORT_PCIV
CORE_FLAGS			= -march=armv7-a -mcpu=cortex-a9
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3536)
ifeq (${SDK_HISIL_3536},)
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3536 Sdk $(SDK_HISIL_3536_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3536 -DHBFL_SUPPORT_PCIV
CORE_FLAGS			= -march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4 -ffunction-sections -mno-unaligned-access -fno-aggressive-loop-optimizations
CFLAGS 				+= $(CORE_FLAGS)
CXXFlAGS 			+= $(CORE_FLAGS)
endif

ifeq ($(PLATFORM), HI3532)
ifeq (${SDK_HISIL_3532},)
ifneq ($(IGNORE_SDK), y)
$(error Hisilicon 3532 Sdk $(SDK_HISIL_3532_DIR_NAME) not found)
endif
endif
INC_LIB_SUFIX		=
CFLAGS				+= -DPLATFORM_HI3532 -DHBFL_SUPPORT_PCIV
endif

ifeq ($(PLATFORM), x86)
CFLAGS				+= -DPLATFORM_X86
endif

ifeq ($(PLATFORM), ambarella)
CFLAGS				+= -DPLATFORM_AMBARELLA
endif

ifeq ($(PLATFORM), montavista)
CFLAGS				+= -DPLATFORM_MONTAVISTA
endif

ifeq ($(PLATFORM), pnx8400)
CFLAGS				+= -DPLATFORM_PNX8400
endif

ifeq ($(PLATFORM), HI3518)
CFLAGS				+= -DPLATFORM_HI3518
CFLAGS 				+= -march=armv5te
endif

ifeq ($(ARCH), arm)
ifneq ($(CROSS_COMPILE), $(CROSS_ARM_HISI_V400))
CFLAGS				+= -mapcs
endif
endif

# These CFLAGS should also define in DrvTmpl.mk for exdrvs
ifeq ($(SMALL_FLASH_SIZE), true)
export USE_UCLIBC	= true
CFLAGS				+= -DHBFL_UCLIBC # TODO remove this flag (only used by mem manager module)
CFLAGS				+= -DPLATFORM_UCLIBC
CFLAGS 				+= -DPLATFORM_SPI_NORFLASH_16M # 16M nor
else
ifeq ($(SINGLE_NOR_FLASH), true)
export USE_UCLIBC	= true
CFLAGS				+= -DHBFL_UCLIBC # TODO remove this flag (only used by mem manager module)
CFLAGS				+= -DPLATFORM_UCLIBC
CFLAGS 				+= -DPLATFORM_SPI_NORFLASH_16M # 16M nor
else
ifeq ($(SINGLE_NAND_FLASH), true)
CFLAGS				+= -DPLATFORM_GLIBC
CFLAGS 				+= -DPLATFORM_NANDFLASH_128M   # 128M nand
else
CFLAGS				+= -DPLATFORM_GLIBC
CFLAGS 				+= -DPLATFORM_SPI_NORFLASH_4M  # 4M nor + 256M nand
endif
endif
endif

ifeq ($(PROJECT_IPC), true)
CFLAGS				+= -DPROJECT_IPC
CFLAGS				+= -DVI_FUNC_ENABLE
CFLAGS				+= -DVOSD_FUNC_ENABLE
CFLAGS				+= -DVENC_FUNC_ENABLE
else
ifeq ($(PROJECT_HVR), true)
CFLAGS				+= -DPROJECT_HVR
CFLAGS				+= -DVI_FUNC_ENABLE
CFLAGS				+= -DVOSD_FUNC_ENABLE
CFLAGS				+= -DVENC_FUNC_ENABLE
CFLAGS				+= -DVO_FUNC_ENABLE
CFLAGS				+= -DVDEC_FUNC_ENABLE
CFLAGS				+= -DVENC_MULTI_CHN_ENABLE
CFLAGS				+= -DVENC_2JPEG_CHN_ENABLE
else
CFLAGS				+= -DPROJECT_NVR
CFLAGS				+= -DVO_FUNC_ENABLE
CFLAGS				+= -DVDEC_FUNC_ENABLE
CFLAGS				+= -DVENC_MULTI_CHN_ENABLE
CFLAGS				+= -DVENC_2JPEG_CHN_ENABLE
endif
endif

ifeq ($(USED_ETH_MULTI), true)
CFLAGS				+= -DNETWORK_BOND_ENABLE
CFLAGS				+= -DNETWORK_DIAGNOSIS_ENABLE
endif

########################################
#
# Setup Hisilicon include/lib path 
# Setup IC related compile flag
# 
########################################
ifeq ($(PLATFORM), HI3536)
ifeq ($(DUAL_CORE_CPU_MODE), true)
HISIL_MPP_PATH := $(HISIL_SDK)/mpp_master
else
HISIL_MPP_PATH := $(HISIL_SDK)/mpp_single
endif
else
HISIL_MPP_PATH := $(HISIL_SDK)/mpp
endif
HISIL_INC_PATH = $(HISIL_MPP_PATH)/include$(INC_LIB_SUFIX)
HISIL_LIB_PATH = $(HISIL_MPP_PATH)/lib$(INC_LIB_SUFIX)
HISIL_DRV_PATH = $(HISIL_MPP_PATH)/ko$(INC_LIB_SUFIX)

CFLAGS			+= -I$(HISIL_INC_PATH) -L$(HISIL_LIB_PATH)
CFLAGS			+= -I$(HISIL_SDK)/mpp/component/pci/include/
CFLAGS			+= -I$(HISIL_SDK)/mpp/component/pci/pciv/kernel/
CFLAGS			+= -I$(HISIL_SDK)/osdrv/drv/pcie_mcc/msg_comm/include/

ifeq ($(BUILD_SLAVE_CHIP), true)
CFLAGS			+= -DHB_SLAVE_CHIP
endif

ifeq ($(SLAVE_CHIP), true)
CFLAGS			+= -DPCIV_ENABLE
endif

export LD_FLAGS		= 
export AR_FLAGS		= -rc

export HB_SVN_INFO	?= $(shell sh $(GET_SRC_RVER_SH) $(TOP_DIR))
CFLAGS				+= -DSRC_REVISION=$(HB_SVN_INFO)_$(BUILD_DATE_TIME)
# vim:noet:sw=4:ts=4

